const R = require('ramda')
const { DataTypes } = require('sequelize')

const createFields = (fields, options = { hasId: true, hasAudit: true }) => {
  const { hasAudit, hasId } = options
  const idField = {
    id: {
      type: DataTypes.STRING(20),
      primaryKey: true,
      comment: '唯一id',
    },
  }
  const auditFields = {
    createdBy: {
      type: DataTypes.STRING(50),
      comment: '创建人',
    },
    updatedBy: {
      type: DataTypes.STRING(50),
      comment: '更新人',
    },
    deletedBy: {
      type: DataTypes.STRING(50),
      comment: '删除人',
    },
  }
  if (hasId) {
    fields = {
      ...fields,
      ...idField,
    }
  }
  if (hasAudit) {
    fields = {
      ...fields,
      ...auditFields,
    }
  }
  return fields
  // return R.clone(fields)
}

module.exports = {
  createFields,
}
